package com.isoftstone.springcloud.framework.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.isoftstone.springcloud.framework.entity.User;
import com.isoftstone.springcloud.framework.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xuyong123
 * @since 2018-05-24
 */
@Controller
@RequestMapping("/user")
public class UserController {

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    public UserService userService;

    @GetMapping("/info")
    @ResponseBody
    public String getUser(){
        List<User> userList = userService.selectList((new EntityWrapper<User>().eq("id",1)));
        return userList.toString();
    }

    @RequestMapping(value = "/trace-2",method = RequestMethod.GET)
    @ResponseBody
    public String trace(HttpServletRequest request){
        logger.info("===<call trace-2,TraceId={},SpanId={}>==="+","+request.getHeader("X-B3-TraceId")+","+request.getHeader("X-B3-SpanId"));
        return "Trace";
    }


}

